package cn.cupk.corporateshuttlemanagesystem.mapper;

import cn.cupk.corporateshuttlemanagesystem.pojo.Buses;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface BusesMapper {

    @Select({
            "<script>",
            "SELECT * FROM buses",
            "<where>",
            "<if test='capacity != null'>",
            "AND capacity LIKE CONCAT('%', #{capacity}, '%')",
            "</if>",
            "<if test='driverName != null'>",
            "AND driver_name LIKE CONCAT('%', #{driverName}, '%')",
            "</if>",
            "</where>",
            "</script>"
    })
    List<Buses> page(Buses data);

    @Select("SELECT * FROM buses WHERE license_plate = #{licensePlate}")
    Buses selectByBusId(String licensePlate);

    @Insert("INSERT INTO buses(license_plate,model,capacity,driver_name,driver_phone,license_number,company_id) VALUES(#{licensePlate},#{model},#{capacity},#{driverName},#{driverPhone},#{licenseNumber},#{companyId})")
    Integer add(Buses data);

    @Update("UPDATE buses set license_plate = #{licensePlate},model = #{model},capacity = #{capacity},driver_name = #{driverName},driver_phone = #{driverPhone},license_number = #{licenseNumber},company_id = #{companyId} WHERE bus_id=#{busId}")
    Integer update(Buses data);






}
